var rec_req_id = "";
function getReqId(url, idx) {
  var str = "req_id="
  var reqid = url.slice(idx + str.length); 
  return reqid;
}

window.bfd_onload = function(){
  if ( null != bfdCode || "" != bfdCode ){
    client = new brs.Client(bfdCode);
    var p = new brs.PackedRequest();
    var url = self.location.href;
    var idx = url.indexOf("req_id=");
    if (idx >= 0) {
      var req_id = getReqId(url, idx); 
      p.cr = new brs.ClickRecItem(rec_user_id, rec_prod_id, rec_session_id, req_id);
    } else {
      p.a = new brs.AddItem(rec_prod_id, rec_prod_name, rec_prod_link,rec_prod_price);
      p.a.image_link = rec_prod_img_url; 
      p.a.price = rec_prod_price; 
      var rec_category_array=rec_category_st.split("|");
      p.a.category = rec_category_array; 
      p.v = new brs.VisitItem(rec_user_id, rec_prod_id, rec_session_id);
    }
    p.rec2 = new brs.RecByViewAlsoView(new Array(rec_prod_id), rec_session_id,35);
    client.invoke(p, "cb_recommend");
  }
}

function cb_recommend(json) {
  var rec2_data = json.rec2[2];
  rec_req_id = json.rec2[1];
  var sku_ids_rec2 = '';
  for (var i in rec2_data){
    sku_ids_rec2 += sku_ids_rec2 == '' ? rec2_data[i] : ',' + rec2_data[i];
  } 
  if ( "" != sku_ids_rec2 ){
    $.post("/ecmall/product/jsonProdRecommend.do",{prodRecommends:sku_ids_rec2},prodRecommendCallback,"json");
  }
}